package my.study.java.basic.init;

public class OverLoadEx01 {
	/**
	 * 重载函数选择，先看引用的类型，如果有符合引用类型的就优先选择 其次看引用类型的父类，最后看可变参数方法
	 */
	public static void main(String[] args) {
		A aa = new A();
		B bb = new B();
		A cc = new B();
		Object dd = new B();

		t(aa);
		t(bb);
		t(cc);
		t(dd);
	}

	static void t(A... a1) {
		System.out.println("t(A...a1)");
		System.out.println(a1[0].print());
	}

	static void t(B... b1) {
		System.out.println("t(B...b1)");
		System.out.println(b1[0].print());
	}

	static void t(B b) {
		System.out.println("t(B b)");
		System.out.println(b.print());
	}

	static void t(A b) {
		System.out.println("t(A b)");
		System.out.println(b.print());
	}

	static void t(Object b) {
		System.out.println("t(Object b)");
		System.out.println(b.toString());
	}

}

class A {
	String print() {
		return "A";
	}

	public String toString() {
		return print();
	}
}

class B extends A {
	String print() {
		return "B";
	}
}
